package com.withoutwords.ui.drawing;

import java.io.ByteArrayOutputStream;

import com.withoutwords.R;
import com.withoutwords.engine.Common;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Rect;
import android.util.DisplayMetrics;
import android.view.ViewGroup;

public abstract class BaseDrawingController {
	
	//protected static final int drawingBitmapBaseWidth = 735;
	protected static final float drawingBitmapHeightRatio = 0.6125f;
	
	
	protected int drawingBitmapWidth = 0;
	protected int drawingBitmapHeight = 0;
	
	protected static final int sendingBitmapWidth = 200;
	protected static final int sendingBitmapHeight = 200;
	protected BaseDrawingController()
	{
		
	}
	boolean bViewOnlyMode;
	Context mContext;
	public void initializeViews(Context context,ViewGroup parent,boolean bViewOnly)
	{
		mContext = context;
		DisplayMetrics metrics  = context.getResources().getDisplayMetrics();
		if(drawingBitmapHeight == 0)
		{
			drawingBitmapHeight = (int)(drawingBitmapHeightRatio* metrics.heightPixels);
			drawingBitmapWidth = drawingBitmapHeight;
		}
		
	}
	
	public abstract void undo();
	public abstract void onEraseModeActiviated();
	public abstract void onSettingsRequested();
	public abstract byte[] getDrawingBytesToSend();
	public abstract void setCurrentDrawing(byte[] data);
	public abstract void clearCurrentDrawing();
	

	protected byte[] addDrawingtoBackground(Context context,Bitmap drawing)
	{
		Bitmap bmp = BitmapFactory.decodeResource(context.getResources(), R.drawable.drawing_bg);
		Bitmap iconBmp = BitmapFactory.decodeResource(context.getResources(), R.drawable.icon);
		//Bitmap drawingBitmap = Bitmap.createBitmap(bmp.copy(Bitmap.Config.ARGB_8888, true));
		Bitmap drawingBitmap = Bitmap.createBitmap(drawing.getWidth(), drawing.getHeight(), drawing.getConfig());
		Canvas canvas = new Canvas(drawingBitmap);
		canvas.drawBitmap(bmp, new Rect(0, 0, drawing.getWidth(), drawing.getWidth()), new Rect(0, 0, drawing.getWidth(), drawing.getHeight()), null);
		
	
		
		Paint paint = new Paint();
		paint.setTypeface(Common.getTypeface(context));
		paint.setTextSize(36);
		paint.setColor(0xEEFFFFFF);
		int yPos  = drawingBitmap.getHeight()-60;
		canvas.drawText("www.facebook.com/ActNGuess", 20,yPos, paint);
		
		yPos  = drawingBitmap.getHeight()-100;
		canvas.drawBitmap(iconBmp,  drawing.getWidth() - 100, yPos, null);
		//drawing.setHasAlpha(true);
		
		
		canvas.drawBitmap(drawing,0.0f,0.0f,null);
		
		 ByteArrayOutputStream baos = new ByteArrayOutputStream();
         drawingBitmap.compress(Bitmap.CompressFormat.JPEG, 100, baos);
          byte []data = baos.toByteArray();
          return data;
	}
	public abstract byte[] getDrawingBytesToShare();

	
}
